<?php
namespace  app\home\controller;
use think\Db;
use EasyWeChat\Foundation\Application;
use think\Config;
use org\Qiniu;
/**
 * 资讯
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2018/9/4
 * Time: 11:03
 */
class Information extends Common {
    //首页
    public function index(){
        session('target_url',"http://south.xuanwumobile.com/home/Information/index");
        $openid = $this->getOpenid();
        $this->getUserId($openid);
        $page = input('param.page')?input('param.page'):1;
        //资讯分类
        $cate = Db::table('up_information_type')->select();
        //资讯分类ID
        $cate_id = input('param.cate_id')?input('param.cate_id'):$cate[0]['information_type_id'];

        //资讯结果
        $list = Db::table('up_information i')
            ->join('up_mechanism m','i.mechanism_id = m.mechanism_id','left')
            ->where(['information_type_id'=>$cate_id,'information_status'=>1])
            ->field('i.mechanism_for,i.information_id,i.information_title,i.information_img,i.information_introduce,i.information_release_time,m.mechanism_id,m.mechanism_name')
            ->page($page,10)
            ->order('information_release_time desc')
            ->select();
        foreach ($list as  $key=>&$vv){
            $start_time = date('Ymd',strtotime($vv['information_release_time']));
            if($start_time==date('Ymd',time())){//同年同月同日
                $vv['information_release_time'] = date('m-d',strtotime($vv['information_release_time'])).'   '.date('H:i',strtotime($vv['information_release_time']));
            }elseif (date('Y',strtotime($vv['information_release_time']))!=date('Y',time())){
                //不同年
                $vv['information_release_time'] = date('Y-m-d',strtotime($vv['information_release_time'])).'  '.date('H:i',strtotime($vv['information_release_time']));
            }else{
                $vv['information_release_time'] = date('m-d',strtotime($vv['information_release_time'])).'  '.date('H:i',strtotime($vv['information_release_time']));
            }
        }
        $this->assign('cate',$cate);
        $this->assign('list',$list);
        $this->assign('cate_id',$cate_id);
        return $this->fetch();
    }

    /**
     * ajax请求资讯
     */
    public function ajaxInformation(){
        $page = input('param.page')?input('param.page'):1;
        $cate_id = input('param.cate_id');
        $list = Db::table('up_information i')
            ->join('up_mechanism m','i.mechanism_id = m.mechanism_id','left')
            ->where(['information_type_id'=>$cate_id,'information_status'=>1])
            ->field('i.mechanism_for,i.information_id,i.information_title,i.information_img,i.information_introduce,i.information_release_time,m.mechanism_id,m.mechanism_name')
            ->page($page,10)
            ->order('information_release_time desc')
            ->select();
        foreach ($list as  $key=>&$vv){
            $start_time = date('Ymd',strtotime($vv['information_release_time']));
            if($start_time==date('Ymd',time())){//同年同月同日
                $vv['information_release_time'] = date('m-d',strtotime($vv['information_release_time'])).'   '.date('H:i',strtotime($vv['information_release_time']));
            }elseif (date('Y',strtotime($vv['information_release_time']))!=date('Y',time())){
                //不同年
                $vv['information_release_time'] = date('Y-m-d',strtotime($vv['information_release_time'])).'  '.date('H:i',strtotime($vv['information_release_time']));
            }else{
                $vv['information_release_time'] = date('m-d',strtotime($vv['information_release_time'])).'  '.date('H:i',strtotime($vv['information_release_time']));
            }
        }
        return json(['status'=>200,'msg'=>$list]);

    }

    /***
     * 详情页面
     */
    public function detail(){
        $page = input('param.page')?input('param.page'):1;
        session('target_url',"http://south.xuanwumobile.com/home/Information/detail?page=".$page);
        $openid = $this->getOpenid();
        $this->getUserId($openid);

        $user_id = session('u_openid');
        $id = input('param.id');
        $mechanism_id = Db::table('up_information')->where('information_id',$id)->value('mechanism_id');
        if($mechanism_id == 1){//该咨询是总队发布
            $detail = Db::table('up_information i')
                ->join('up_mechanism m','i.mechanism_id = m.mechanism_id','left')
                ->join('up_admin ua', 'ua.id = i.admin_id', 'left')
                ->where('i.information_id',$id)
                ->field('i.information_id,i.information_title,i.information_content,
                i.information_img,i.information_introduce,i.information_release_time,
                m.mechanism_id,m.mechanism_name, ua.real_name as name')
                ->find();
        }else{
            $detail = Db::table('up_information i')
                ->join('up_mechanism m','i.mechanism_id = m.mechanism_id','left')
                ->join('up_mechanism_member umm', 'umm.id = i.admin_id', 'left')
                ->where('i.information_id',$id)
                ->field('i.information_id,i.information_title,i.information_content,
                i.information_img,i.information_introduce,i.information_release_time,
                m.mechanism_id,m.mechanism_name, umm.mechanism_member_name as name')
                ->find();
        }

        $start_time1 = date('Ymd',strtotime($detail['information_release_time']));
        if($start_time1==date('Ymd',time())){//同年同月同日
            $detail['information_release_time'] = date('m-d',strtotime($detail['information_release_time'])).'   '.date('H:i',strtotime($detail['information_release_time']));
        }elseif (date('Y',strtotime($detail['information_release_time']))!=date('Y',time())){
            //不同年
            $detail['information_release_time'] = date('Y-m-d',strtotime($detail['information_release_time'])).'  '.date('H:i',strtotime($detail['information_release_time']));
        }else{
            $detail['information_release_time'] = date('m-d',strtotime($detail['information_release_time'])).'  '.date('H:i',strtotime($detail['information_release_time']));
        }
        if($user_id != 0){
            $res = Db::table('up_my_collection')
                ->where(['user_id'=>$user_id,'information_id'=>$id])
                ->find();
            if(!empty($res) && !empty($detail)){
                $detail['collection'] = 1;//收藏
            }elseif(!empty($detail)){
                $detail['collection'] = 2;//没有收藏
            }
        }
        //评论
        $answer  = Db::table('up_information_answer a')
        ->join('up_u_user u','a.answer_user_id = u.user_id','left')
            ->where(['answer_information_id'=>$id])
            ->field('a.answer_user_id,a.answer_id, a.answer_content, a.answer_img, a.answer_dz, a.answer_information_id, 
            a.answer_time,u.user_id,u.user_username, u.user_image')
            ->page($page,2)
            ->order('a.answer_time desc')
            ->select();
        $num  = Db::table('up_information_answer a')
            ->join('up_u_user u','a.answer_user_id = u.user_id','left')
            ->where(['answer_information_id'=>$id])
            ->count();
        $detail['num'] = $num;//评论数量
        foreach($answer as $key=>&$vo){
            $res = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$vo['answer_id'],'type'=>3])->find();
            if($res){
                $vo['dz'] = 1;//点赞过了
            }else{
                $vo['dz'] = 2;//没有点赞
            }
            if($vo['answer_user_id'] == $user_id){
                $vo['delete'] = 1;//可以删除
            }else{
                $vo['delete'] = 2;//不可以删除
            }

            //转换图片为数组
            $vo['answer_img'] = trim($vo['answer_img'], ',');
            if(!empty($vo['answer_img'])){
                $vo['answer_img'] = explode(',', $vo['answer_img']);
            }else{
                $vo['answer_img'] = [];
            }
            $start_time = date('Ymd',strtotime($vo['answer_time']));
            if($start_time==date('Ymd',time())){//同年同月同日
                $vo['answer_time'] = date('m-d',strtotime($vo['answer_time'])).'   '.date('H:i',strtotime($vo['answer_time']));
            }elseif (date('Y',strtotime($vo['answer_time']))!=date('Y',time())){
                //不同年
                $vo['answer_time'] = date('Y-m-d',strtotime($vo['answer_time'])).'  '.date('H:i',strtotime($vo['answer_time']));
            }else{
                $vo['answer_time'] = date('m-d',strtotime($vo['answer_time'])).'  '.date('H:i',strtotime($vo['answer_time']));
            }
        }

        /*二级评论*/
            foreach($answer as $keys=>&$vos){
                $reply = Db::table('up_information_answer_reply r')
                    ->join('up_u_user u2','r.reply_answer_user_id = u2.user_id','left')
                    ->where(['r.reply_information_answer_id'=>$vos['answer_id']])
                    ->field('r.*,u2.user_username name2')
                    ->limit(3)
                    ->order('r.reply_create_time desc')
                    ->select();
                foreach($reply as $k=>&$v){

                   // $res = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$v['reply_id'],'type'=>4])->find();
//                    if(!empty($res)){
//                        $v['dzr'] = 1;//点赞
//                    }else{
//                        $v['dzr'] = 2;//没有点赞
//                    }
                    //转换图片为数组
                    $v['reply_image'] = trim($v['reply_image'], ',');
                    if(!empty($vo['reply_image'])){
                        $v['reply_image'] = explode(',', $v['reply_image']);
                    }else{
                        $v['reply_image'] = [];
                    }
                    if($v['reply_answer_user_id'] == $user_id){
                        $v['is_delete'] = 1;//可以删除
                    }else{
                        $v['is_delete'] =2;//不可以删除
                    }
                }
                $count = Db::table('up_information_answer_reply r')
                    ->join('up_u_user u','r.reply_user_id = u.user_id','left')
                    ->join('up_u_user u2','r.reply_answer_user_id = u2.user_id','left')
                    ->where(['r.reply_information_answer_id'=>$vos['answer_id']])
                    ->count();
                $vos['under'] = $reply;
                $vos['count'] = $count;
            }
        $detail['answer'] = $answer;
        $this->assign('detail',$detail);
        $this->assign('id',$id);
        return $this->fetch();
    }

    /***
     * ajax资讯详情页面
     */
    public function ajaxdetail(){
        $user_id = session('u_openid');
        $page = input('param.page')?input('param.page'):1;

        $id = input('param.id');
        //评论

        $answer  = Db::table('up_information_answer a')
            ->join('up_u_user u','a.answer_user_id = u.user_id','left')
            ->where(['answer_information_id'=>$id])
            ->field('a.answer_user_id,a.answer_id, a.answer_content, a.answer_img, a.answer_dz, a.answer_information_id, 
            a.answer_time,u.user_id,u.user_username, u.user_image')
            ->page($page,2)
            ->order('a.answer_time desc')
            ->select();
        $num  = Db::table('up_information_answer a')
            ->join('up_u_user u','a.answer_user_id = u.user_id','left')
            ->where(['answer_information_id'=>$id])
            ->count();
        $detail['num'] = $num;//评论数量
        foreach($answer as $key=>&$vo){
            $res = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$vo['answer_id'],'type'=>3])->find();
            if($res){
                $vo['dz'] = 1;//点赞过了
            }else{
                $vo['dz'] = 2;//没有点赞
            }
            if($vo['answer_user_id'] == $user_id){
                $vo['delete'] = 1;//可以删除
            }else{
                $vo['delete'] = 2;//不可以删除
            }

            //转换图片为数组
            $vo['answer_img'] = trim($vo['answer_img'], ',');
            if(!empty($vo['answer_img'])){
                $vo['answer_img'] = explode(',', $vo['answer_img']);
            }else{
                $vo['answer_img'] = [];
            }
            $start_time = date('Ymd',strtotime($vo['answer_time']));
            if($start_time==date('Ymd',time())){//同年同月同日
                $vo['answer_time'] = date('m-d',strtotime($vo['answer_time'])).'   '.date('H:i',strtotime($vo['answer_time']));
            }elseif (date('Y',strtotime($vo['answer_time']))!=date('Y',time())){
                //不同年
                $vo['answer_time'] = date('Y-m-d',strtotime($vo['answer_time'])).'  '.date('H:i',strtotime($vo['answer_time']));
            }else{
                $vo['answer_time'] = date('m-d',strtotime($vo['answer_time'])).'  '.date('H:i',strtotime($vo['answer_time']));
            }
        }

        /*二级评论*/
        foreach($answer as $keys=>&$vos){
            $reply = Db::table('up_information_answer_reply r')
                ->join('up_u_user u2','r.reply_answer_user_id = u2.user_id','left')
                ->where(['r.reply_information_answer_id'=>$vos['answer_id']])
                ->field('r.*,u2.user_username name2')
                ->limit(3)
                ->order('r.reply_create_time desc')
                ->select();
            foreach($reply as $k=>&$v){

                 $res = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$v['reply_id'],'type'=>4])->find();
                    if(!empty($res)){
                        $v['dzr'] = 1;//点赞
                    }else{
                        $v['dzr'] = 2;//没有点赞
                    }
                //转换图片为数组
                $v['reply_image'] = trim($v['reply_image'], ',');
                if(!empty($vo['reply_image'])){
                    $v['reply_image'] = explode(',', $v['reply_image']);
                }else{
                    $v['reply_image'] = [];
                }
                if($v['reply_answer_user_id'] == $user_id){
                    $v['is_delete'] = 1;//可以删除
                }else{
                    $v['is_delete'] =2;//不可以删除
                }
            }
            $count = Db::table('up_information_answer_reply r')
                ->join('up_u_user u','r.reply_user_id = u.user_id','left')
                ->join('up_u_user u2','r.reply_answer_user_id = u2.user_id','left')
                ->where(['r.reply_information_answer_id'=>$vos['answer_id']])
                ->count();
            $vos['under'] = $reply;
            $vos['count'] = $count;
        }
        return json(['status'=>200,'msg'=>$answer]);

    }

    /**
     * 发表评论
     */
    public function addComment(){
            //todo 缺少用户ID
            $user_id = session('u_openid');
            $time = date('Y-m-d H:i:s');
            $content = input('param.content');
            $answer_id = input('param.answer_id');
            $param = [
                'reply_information_answer_id'=>$answer_id,
                'reply_answer_user_id'=>$user_id,
                'reply_content'=>$content,
                'reply_create_time'=>$time,
            ];
            $table = 'up_information_answer_reply';

        $res = Db::table($table)->insert ($param);
        if($res){
            $this->apiSuccess ();
        }else{
            $this->apiError (100,'评论失败');
        }
    }
    /**
     * 评论点赞 &取消点赞
     * @throws \think\Exception
     */
    public function like(){
        $user_id = session('u_openid');
        $id = input('param.id');
        $type = input('param.type');
        extract(input());
        if($type == 1){/*type = 1对文章评论*/
            $table = 'up_information_answer';
            $field = 'answer_dz';
            $where = ['answer_id'=>$id];
            $t = 3;
        }elseif($type == 2){//对评论评论
            $table = 'up_information_answer_reply';
            $field = 'reply_thumbs_up';
            $where = ['reply_id'=>$id];
            $t = 4;
        }
        $res = Db::table('up_dz')->where(['user_id'=>$user_id,'type'=>$t,'data_id'=>$id])->find();
        if(!empty($res)){
            // 启动事务
            Db::startTrans();
            try{
                Db::table('up_dz')->where(['user_id'=>$user_id,'type'=>$t,'data_id'=>$id])->delete();
                Db::table($table)->where($where)->setDec ($field);
                Db::commit();
                $this->apiSuccess ('取消点赞成功');
            } catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                $this->apiError (100,'取消点赞失败');
            }
        }else{
            // 启动事务
            Db::startTrans();
            try{
                Db::table($table)->where($where)->setInc ($field);
                Db::table('up_dz')->insert(['user_id'=>$user_id,'type'=>$t,'data_id'=>$id]);
                // 提交事务
                Db::commit();
                $this->apiSuccess ('点赞成功');
            } catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                $this->apiError (100,'点赞失败');
            }
        }
    }
    /**
     * 收藏资讯
     */
    public function collect(){
        extract (input());
        $user_id = session('u_openid');
        $information_id = input('param.id');
        $res = Db::table('up_my_collection')
            ->where('user_id', $user_id)
            ->where('information_id', $information_id)
            ->find();

        if($res){//已收藏，点击取消收藏
            $result = Db::table('up_my_collection')
                ->where('collection_id', $res['collection_id'])
                ->delete();
            if(!$result){//取消收藏失败
                return $this->apiError(4005);
            }
            $collect = 2;//是否收藏  1已收藏  2未收藏
        }else{//未收藏，点击添加收藏
            $data = [
                'user_id' => $user_id,
                'information_id' => $information_id,
                'create_time' => date('Y-m-d H:i:s')
            ];
            $result = Db::table('up_my_collection')
                ->insert($data);
            if(!$result){//添加收藏失败
                return $this->apiError(4005);
            }
            $collect = 1;//是否收藏  1已收藏  2未收藏
        }
        return $this->apiSuccess(['collect'=>$collect]);
    }

    /**
     * 删除评论/回复
     * type：删除的记录类型   评论 1   回复 2
     * id：被删除记录的ID
     */
    public function delAnswer(){
        $params = input('param.');
        $type = $params['type'];
        if($type == 1){//删除评论
            $res = Db::table('up_information_answer')->where('answer_id', $params['id'])->delete();
            $count = Db::table('up_information_answer_reply')->where('reply_information_answer_id', $params['id'])->count();
            if(count($count)>0){
               Db::table('up_information_answer_reply')->where('reply_information_answer_id', $params['id'])->delete();
            }
        }else{//删除回复
            $res = Db::table('up_information_answer_reply')->where('reply_id', $params['id'])->delete();
        }
        if($res){
            $this->apiSuccess();
        }else{
            $this->apiError('E001');
        }
    }

    /***
     * @return mixed
     *资讯详情
     */
    public function answerdatail(){
        $page = input('param.page')?input('param.page'):1;
        $answer_id = input('param.answer_id');
        session('target_url',"http://south.xuanwumobile.com/home/Information/answerdatail?page=".$page.'&answer_id='.$answer_id);
        $openid = $this->getOpenid();
        $this->getUserId($openid);

        $num = $page - 1;
        $user_id = session('u_openid');

        $res = Db::table('up_information_answer')->alias('a')
            ->join('up_u_user uuu','uuu.user_id=a.answer_user_id','left')
            ->field('uuu.user_username,uuu.user_image,a.*')
            ->where('answer_id',$answer_id)->find();
        $aa = explode(',',trim($res['answer_img'],','));
        if(count(array_filter($aa))>0){
            $res['answer_img'] = $aa;
        }else{
            $res['answer_img'] = array();
        }
        if($user_id==$res['answer_user_id']){
            $res['is_delete'] =1;//可以删除
        }else{
            $res['is_delete'] = 2;//不可以
        }

        $ress = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$res['answer_id'],'type'=>3])->find();
        if($ress){
            $res['dz'] = 1;//点赞过了
        }else{
            $res['dz'] = 2;//没有点赞
        }
        $day = date('Y-m-d',time());//当前时间
        $time = time() - 3600*24;//昨天的时间戳
        $last_time = date('Y-m-d 00:00:00',$time);//昨天开始
        $last_time1 = date('Y-m-d 23:59:59',$time);//昨天结束
        if($day==date('Y-m-d',strtotime($res['answer_time']))){//判断是否是今天
            $res['answer_time'] ='今天'.' '.date('H:i',strtotime($res['answer_time']));
        }elseif ($last_time<$res['answer_time']&&$res['answer_time']<$last_time1)
        {//判断是否是昨天
            $res['answer_time'] ='昨天'.' '.date('m-d H:i',strtotime($res['answer_time']));
        }
        //多少条回复
        $count = Db::table('up_information_answer_reply')
                    ->alias('a')
                    ->join('up_u_user uuu','uuu.user_id = a.reply_user_id','left')
                    ->where('a.reply_information_answer_id',$answer_id)
                    ->count();
        $res['count'] = $count;

        $reply = Db::table('up_information_answer_reply r')
            ->join('up_u_user u2','r.reply_answer_user_id = u2.user_id','left')
            ->where(['r.reply_information_answer_id'=>$res['answer_id']])
            ->field('r.*,u2.user_username name2,u2.user_image')
            ->limit($num*10,10)
            ->order('r.reply_create_time desc')
            ->select();
        foreach($reply as $k=>&$v){
         $result = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$v['reply_id'],'type'=>4])->find();
                if(!empty($result)){
                    $v['dzr'] = 1;//点赞
                }else{
                    $v['dzr'] = 2;//没有点赞
                }
            if($v['reply_answer_user_id'] == $user_id){
                $v['is_delete'] = 1;//可以删除
            }else{
                $v['is_delete'] =2;//不可以删除
            }
        }
        $res['under'] = $reply;
        $this->assign('res',$res);
        $this->assign('id',$answer_id);
        $this->assign('answer_information_id',$res['answer_information_id']);
        return $this->fetch();
    }

    /***
     * @return \think\response\Json
     * 加载更多评论
     */
    public function ajaxmoreanswer(){
        $user_id =session('u_openid');
        $page = input('param.page')?input('param.page'):1;
        $num = $page - 1;
        $answer_id = input('param.answer_id');
        $reply = Db::table('up_information_answer_reply r')
            ->join('up_u_user u2','r.reply_answer_user_id = u2.user_id','left')
            ->where(['r.reply_information_answer_id'=>$answer_id])
            ->field('r.*,u2.user_username name2,u2.user_image')
            ->limit($num*10,10)
            ->order('r.reply_create_time desc')
            ->select();
        foreach($reply as $k=>&$v){
            $result = Db::table('up_dz')->where(['user_id'=>$user_id,'data_id'=>$v['reply_id'],'type'=>4])->find();
            if(!empty($result)){
                $v['dzr'] = 1;//点赞
            }else{
                $v['dzr'] = 2;//没有点赞
            }
            if($v['reply_answer_user_id'] == $user_id){
                $v['is_delete'] = 1;//可以删除
            }else{
                $v['is_delete'] =2;//不可以删除
            }
        }
        return json(['status'=>200,'msg'=>$reply]);

    }

    /***
     * @return mixed
     * 我来回答
     */
    public function question(){
        $id = input('param.id');
        //微信
        session('target_url',"http://south.xuanwumobile.com/home/Information/question?id=".$id);
        $openid = $this->getOpenid();
        $this->getUserId($openid);
        $options = Config::get('wechat');
        $app = new Application($options);
        $js = $app->js;
        $json = $js->config(array('getLocation','chooseImage','uploadImage','downloadImage','getLocalImgData'), false ,false,true);
        $this->assign(['json'=>$json,'uid'=>input('uid')]);
        $this->assign('id',$id);
        return $this->fetch();
    }
    /***
     * @return \think\response\Json
     * 问答插入数据
     */
    public function addwd(){
        extract(input());
        $up = new Qiniu();
        $arr = '';
        if(isset($photo)){
            foreach($photo as $key=>$vo){
                $img = base64_img1 ($vo)['msg'];
                //取出图片后缀
                $type = explode(".",$img);
                $type = end($type);
                //组装图片名
                $key = md5(time().uuid()).'.'.$type;
                $arr[] = $up->uploadFile($img,$key,'http://qiniu.verynurse.com/');
                unlink($img);
            }
            $arr = implode (',',$arr).',';
        }

        if(!isset($content)){
            $content = '';
        }
        $param = [
            'answer_user_id'=>session('u_openid'),
            'answer_time'=>date('Y-m-d H:i:s'),
            'answer_content'=>$content,
            'answer_img'=>$arr,
            'answer_dz'=>0,
            'answer_information_id'=>$id
        ];
        $res = Db::name('information_answer')->insert($param);
        if($res){
            return json(['code'=>200,'msg'=>$arr]);
        }else{
            return json(['code'=>100,'msg'=>'回答失败']);
        }
    }

    /***
     * @return mixed
     * 搜索列表
     */
    public function search(){
        //TODO  缺少用户ID
//        $where['search_user_id'] = 44;
//        $list = Db::table('up_user_search')->where($where)->order('search_datetime desc')->limit(5)->select();
//        $this->assign('list',$list);
        return $this->fetch();
    }

    /***
     * @return mixed
     * 搜索结果
     */
    public function searchjg(){
        $keyword = input('param.keyword');
        $page = input('param.page')?$page = input('param.page'):1;
        session('target_url',"http://south.xuanwumobile.com/home/Information/searchjg?keyword=".$keyword.'&page='.$page);
        $openid = $this->getOpenid();
        $this->getUserId($openid);

        if($keyword == ''){
            $list = Db::table('up_information')->alias('ui')
                ->join('up_mechanism um', 'um.mechanism_id = ui.mechanism_id', 'left')
                ->field('ui.mechanism_for,ui.information_img, ui.information_id, ui.information_title, information_introduce, 
            ui.information_release_time, um.mechanism_name')
                ->where('information_status',1)
                ->limit(($page - 1) * 10, 10)
                ->select();
        }else{
            $list = Db::table('up_information')->alias('ui')
                ->join('up_mechanism um', 'um.mechanism_id = ui.mechanism_id', 'left')
                ->field('ui.mechanism_for,ui.information_img, ui.information_id, ui.information_title, information_introduce, 
            ui.information_release_time, um.mechanism_name')
                ->where('information_title', 'like', "%{$keyword}%")
                ->where('information_status',1)
                ->limit(($page - 1) * 10, 10)
                ->select();
        }
        $this->assign('list',$list);
        $this->assign('keyword',$keyword);
        return $this->fetch();
    }
}